package com.citcc.web.controller.business;

import com.citcc.business.bean.CdzAmountDetail;
import com.citcc.business.bean.dto.CdzAmountDetailCon;
import com.citcc.business.service.CdzBalanceLService;
import com.citcc.common.annotation.Log;
import com.citcc.common.base.AjaxResult;
import com.citcc.common.enums.BusinessType;
import com.citcc.common.page.TableDataInfo;
import com.citcc.common.utils.DateUtils;
import com.citcc.common.utils.poi.ExcelUtil;
import com.citcc.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/cdzBalance")
public class CdzBalanceLController extends BaseController {

    private String prefix = "business/cdzBalance";

    @Autowired
    private CdzBalanceLService cdzBalanceLService;

    @RequiresPermissions("business:cdzBalance:view")
    @GetMapping("/main")
    public String main(String flag,ModelMap map){
        if(!"0".equals(flag)){
            CdzAmountDetailCon con = new CdzAmountDetailCon();
            con.setType(flag);
            con.setPayState("2");
            map.put("count",cdzBalanceLService.selectSumDetail(con));
        }
        map.put("flag",flag);
        return prefix + "/main";
    }

    @RequiresPermissions("business:cdzBalance:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(CdzAmountDetailCon con){
        startPage();
        /*if (userOrderEntity.getOrgId()==null||"".equals(userOrderEntity.getOrgId())) {
            userOrderEntity.setOrgId(getSysUser().getDeptId());
        }*/
        List<CdzAmountDetail> list=cdzBalanceLService.selectList(con);
        return getDataTable(list);
    }

    @RequiresPermissions("business:cdzBalance:remove")
    @Log(title = "交易订单管理", businessType = BusinessType.UPDATE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        try
        {
            Integer e =cdzBalanceLService.delete(id);
            return toAjax(e);
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }
    @RequiresPermissions("business:cdzIndent:export")
    @Log(title = "订单导出", businessType = BusinessType.UPDATE)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CdzAmountDetailCon con)
    {
        List<CdzAmountDetail> list=cdzBalanceLService.selectList(con);
        ExcelUtil<CdzAmountDetail> util = new ExcelUtil<CdzAmountDetail>(CdzAmountDetail.class);
        return util.exportExcel(list, DateUtils.dateTimeNow()+"充电订单");
    }

}
